

export class tabHandlingTools
{
    constructor(page, context)
    {
        this.page = page; 
        this.pages = [this.page] ;
        this.context = context ;
    }

    async catchNewPage()
    {
        return this.context.waitForEvent('page', { timeout: 2500}).catch(() => null); 
        /// shouldnt we await this
    }

    async handleTabOpen(newPagePromise)
    {
        const newPage = await newPagePromise;
        if(newPage)
        {
            this.pages.push(newPage);
            this.page.ref = newPage;
        }
    }

    async handleTabClose()
    {
        if(await this.page.ref.isClosed())
        {
            this.pages.pop();
            this.page.ref = this.pages[this.pages.length-1];
        }
    }
}